import cronstrue from 'cronstrue'
import 'cronstrue/locales/zh_CN'
export default {
  text(field, row) {
    let value = row[field.field]
    if (value === null || value === undefined || value === '') {
      return value
    }
    if (field.type.text.regEx) {
      let returnValue = value
      try {
        returnValue = eval(field.type.text.regEx)(value)
      } catch (e) {
        console.error(e)
      }
      return returnValue
    } else {
      return value
    }
  },
  url(field, row) {
    let value = row[field.field]
    if (value === null || value === undefined || value === '') {
      return value
    }
    if (field.type.url.regEx) {
      let regResult = value.match(new RegExp(field.type.url.regEx, 'g'))
      if (regResult) {
        return value.match(new RegExp(field.type.url.regEx, 'g'))[0]
      } else {
        return ''
      }
    } else {
      return value
    }
  },
  selectText(field, row, optionDatas) {
    return optionDatas[field.type.select.optionId].options.filter(
      (opt) => opt.value == row[field.field]
    )[0]?.label
  },
  selectTag(field, row, optionDatas) {
    return optionDatas[field.type.select.optionId].options.filter(
      (opt) => opt.value == row[field.field]
    )[0]?.type
  }
}
